<template>
	<view class="mainbgc">
		<header-top :messageInfo="{typeFlag:true,message:titletext,liner:false}">
			<view class="rightmsg" slot="rightmsg">
				<view class="rightmsg_content flexright" @click="submit">
					<view class="nostrongtext">保存</view>
				</view>
			</view>
		</header-top>
		<view class="ffffff">
			<u-tabs :list="list1" @click="tabfn" :scrollable="false" lineColor="#09bcca" :activeStyle="{
            color: '#09bcca',
            fontWeight: 'bold',
            transform: 'scale(1.05)'
        }"></u-tabs>
		</view>

		<!-- 基本信息 -->
		<view v-show="tabcurrent==0">
			<view class="mainpadding">
				<view class="strongtext">
					<text class="titletext textliner">基本信息</text>
				</view>
			</view>
			<view class="ffffff radius mainpadding">
				<view class="inputbox">
					<view class="flexleft flex1">
						<view class="strongtext margin_right">商品名称</view>
					</view>
					<view class="itembox">
						<input type="text" placeholder="请输入商品名称" v-model="name">
					</view>
				</view>
				<view class="inputbox margin_top">
					<view class="flexleft flex1">
						<view class="strongtext margin_right">商品助记名</view>
					</view>
					<view class="itembox">
						<input type="text" placeholder="请输入商品助记名" v-model="zj_name">
					</view>
				</view>
				<view class="inputbox margin_top" @click="spFenLeiShow = true">
					<view class="flexleft flex1">
						<view class="strongtext margin_right">分类</view>
					</view>
					<view class="itembox flexbetween">
						<input type="text" placeholder="请选择商品分类" v-model="spFenLeiText" disabled="">
						<view class="righticon2"></view>
					</view>
				</view>
				<view class="inputbox margin_top" @click="spPinPaiShow = true">
					<view class="flexleft flex1">
						<view class="strongtext margin_right">商品品牌</view>
					</view>
					<view class="itembox flexbetween">
						<input type="text" placeholder="请选择商品品牌" v-model="spPinPaiText" disabled="">
						<view class="righticon2"></view>
					</view>
				</view>
				<view class="inputbox margin_top">
					<view class="flexleft flex1">
						<view class="strongtext">允许改价</view>
					</view>
					<view class="itembox">
						<u-radio-group v-model="allow_gj" placement="row" circle>
							<u-radio activeColor="#0BBDCB" :customStyle="{marginRight: '30rpx'}" label="不允许"
								name="0"></u-radio>
							<u-radio activeColor="#0BBDCB" label="允许" name="1"></u-radio>
						</u-radio-group>
					</view>
				</view>
				<view class="inputbox margin_top">
					<view class="flexleft flex1">
						<view class="strongtext">状态</view>
					</view>
					<view class="itembox">
						<u-radio-group v-model="status" placement="row" circle>
							<u-radio activeColor="#0BBDCB" :customStyle="{marginRight: '30rpx'}" label="上架"
								name="normal"></u-radio>
							<u-radio activeColor="#0BBDCB" label="下架" name="hidden"></u-radio>
						</u-radio-group>
					</view>
				</view>
				<view class="inputbox margin_top">
					<view class="flexleft flex1">
						<view class="strongtext">小程序是否上架</view>
					</view>
					<view class="itembox">
						<u-radio-group v-model="xcx_status" placement="row" circle>
							<u-radio activeColor="#0BBDCB" :customStyle="{marginRight: '30rpx'}" label="否"
								name="hidden"></u-radio>
							<u-radio activeColor="#0BBDCB" label="是" name="normal"></u-radio>
						</u-radio-group>
					</view>
				</view>
				<view class="inputbox margin_top">
					<view class="flexleft flex1">
						<view class="strongtext margin_right">小单位条码</view>
					</view>
					<view class="itembox flexbetween">
						<input type="text" placeholder="请输入小单位条码" v-model="small_goods_unit_code">
						<view class="scan2" @click="scanbarCode(1)"></view>
					</view>
				</view>
				<view class="inputbox margin_top" @click="selechDanWeiFn(1)">
					<view class="flexleft flex1">
						<view class="strongtext margin_right">小单位</view>
					</view>
					<view class="itembox flexbetween">
						<input type="text" placeholder="请选择小单位" v-model="spDanWeixiao" disabled="">
						<view class="righticon2"></view>
					</view>
				</view>
				<view class="inputbox margin_top">
					<view class="flexleft flex1">
						<view class="strongtext margin_right">大单位条码</view>
					</view>
					<view class="itembox flexbetween">
						<input type="text" placeholder="请输入大单位条码" v-model="big_goods_unit_code">
						<view class="scan2" @click="scanbarCode(2)"></view>
					</view>
				</view>
				<view class="inputbox margin_top" @click="selechDanWeiFn(3)">
					<view class="flexleft flex1">
						<view class="strongtext margin_right">大单位</view>
					</view>
					<view class="itembox flexbetween">
						<input type="text" placeholder="请选择大单位" v-model="spDanWeida" disabled="">
						<view class="righticon2"></view>
					</view>
				</view>
				<view class="inputbox margin_top" v-if="spDanWeida">
					<view class="flexleft flex1">
						<view class="strongtext margin_right">中单位条码</view>
					</view>
					<view class="itembox flexbetween">
						<input type="text" placeholder="请输入中单位条码" v-model="middle_goods_unit_code">
						<view class="scan2" @click="scanbarCode(3)"></view>
					</view>
				</view>
				<view class="inputbox margin_top" @click="selechDanWeiFn(2)" v-if="spDanWeida">
					<view class="flexleft flex1">
						<view class="strongtext margin_right">中单位</view>
					</view>
					<view class="itembox flexbetween">
						<input type="text" placeholder="请选择中单位" v-model="spDanWeizhong" disabled="">
						<view class="righticon2"></view>
					</view>
				</view>
				<!-- 大单位数据 -->
				<view class="mainpadding_top itemsku radius" v-if="spDanWeida">
					<view class="namecolor">大单位:{{spDanWeida}}</view>
					<view class="flexbetween margin_top ">
						<view class="radius ffffff flexleft mainpadding iteminput">
							批发价:
							<input type="number" v-model="spec.bigdata.pf_price">
						</view>
						<view class="radius ffffff flexleft mainpadding iteminput">
							零售价:
							<input type="number" v-model="spec.bigdata.price">
						</view>
					</view>
					<view class="flexbetween margin_top ">
						<view class="radius ffffff flexleft mainpadding iteminput">
							最低零售价:
							<input type="digit" style="max-width: 80rpx;" v-model="spec.bigdata.min_price">
						</view>
						<view class="radius ffffff flexleft mainpadding iteminput">
							进价:
							<input type="digit" v-model="spec.bigdata.purchase_price">
						</view>
					</view>
					<view class="flexbetween margin_top ">
						<view class="radius ffffff flexleft mainpadding iteminput">
							成本价:
							<input type="digit" v-model="spec.bigdata.cost_price">
						</view>
						<view class="radius ffffff flexleft mainpadding iteminput">
							重量:
							<input type="digit" v-model="spec.bigdata.weigh">
						</view>
					</view>
					<view class="flexbetween margin_top ">
						<view class="radius ffffff flexleft mainpadding iteminput">
							库存预警:
							<input type="number" v-model="spec.bigdata.yg_stock">
						</view>
						<view class="radius ffffff flexleft mainpadding iteminput">
							兑换积分:
							<input type="digit" v-model="spec.bigdata.dh_score">
						</view>
					</view>
					<view class="radius margin_top ffffff flexleft mainpadding iteminput">
						购买赠积分:
						<input type="digit" style="max-width: 80rpx;" v-model="spec.bigdata.buy_send_score">
					</view>
				</view>
				<!-- 中单位数据 -->
				<view class="mainpadding_top itemsku radius" v-if="spDanWeizhong">
					<view class="namecolor">中单位:{{spDanWeizhong}}</view>
					<view class="flexbetween margin_top ">
						<view class="radius ffffff flexleft mainpadding iteminput">
							批发价:
							<input type="number" v-model="spec.middledata.pf_price">
						</view>
						<view class="radius ffffff flexleft mainpadding iteminput">
							零售价:
							<input type="number" v-model="spec.middledata.price">
						</view>
					</view>
					<view class="flexbetween margin_top ">
						<view class="radius ffffff flexleft mainpadding iteminput">
							最低零售价:
							<input type="number" style="max-width: 80rpx;" v-model="spec.middledata.min_price">
						</view>
						<view class="radius ffffff flexleft mainpadding iteminput">
							进价:
							<input type="number" v-model="spec.middledata.purchase_price">
						</view>
					</view>
					<view class="flexbetween margin_top ">
						<view class="radius ffffff flexleft mainpadding iteminput">
							成本价:
							<input type="number" v-model="spec.middledata.cost_price">
						</view>
						<view class="radius ffffff flexleft mainpadding iteminput">
							重量:
							<input type="text" v-model="spec.middledata.weigh">
						</view>
					</view>
					<view class="flexbetween margin_top ">
						<view class="radius ffffff flexleft mainpadding iteminput">
							库存预警:
							<input type="number" v-model="spec.middledata.yg_stock">
						</view>
						<view class="radius ffffff flexleft mainpadding iteminput">
							兑换积分:
							<input type="digit" v-model="spec.middledata.dh_score">
						</view>
					</view>
					<view class="radius margin_top ffffff flexleft mainpadding iteminput">
						购买赠积分:
						<input type="text" style="max-width: 80rpx;" v-model="spec.middledata.buy_send_score">
					</view>
				</view>
				<!-- 小单位数据 -->
				<view class="mainpadding_top itemsku radius" v-if="spDanWeixiao">
					<view class="namecolor">小单位:{{spDanWeixiao}}</view>
					<view class="flexbetween margin_top ">
						<view class="radius ffffff flexleft mainpadding iteminput">
							批发价:
							<input type="number" v-model="spec.smalldata.pf_price">
						</view>
						<view class="radius ffffff flexleft mainpadding iteminput">
							零售价:
							<input type="number" v-model="spec.smalldata.price">
						</view>
					</view>
					<view class="flexbetween margin_top ">
						<view class="radius ffffff flexleft mainpadding iteminput">
							最低零售价:
							<input type="number" style="max-width: 80rpx;" v-model="spec.smalldata.min_price">
						</view>
						<view class="radius ffffff flexleft mainpadding iteminput">
							进价:
							<input type="number" v-model="spec.smalldata.purchase_price">
						</view>
					</view>
					<view class="flexbetween margin_top ">
						<view class="radius ffffff flexleft mainpadding iteminput">
							成本价:
							<input type="number" v-model="spec.smalldata.cost_price">
						</view>
						<view class="radius ffffff flexleft mainpadding iteminput">
							重量:
							<input type="text" v-model="spec.smalldata.weigh">
						</view>
					</view>
					<view class="flexbetween margin_top ">
						<view class="radius ffffff flexleft mainpadding iteminput">
							库存预警:
							<input type="number" v-model="spec.smalldata.yg_stock">
						</view>
						<view class="radius ffffff flexleft mainpadding iteminput">
							兑换积分:
							<input type="digit" v-model="spec.smalldata.dh_score">
						</view>
					</view>
					<view class="radius margin_top ffffff flexleft mainpadding iteminput">
						购买赠积分:
						<input type="text" style="max-width: 80rpx;" v-model="spec.smalldata.buy_send_score">
					</view>
				</view>
				<view class="inputbox margin_top">
					<view class="flexleft flex1">
						<view class="strongtext">生产日期状态</view>
					</view>
					<view class="itembox">
						<u-radio-group v-model="producedate_status" placement="row" circle>
							<u-radio activeColor="#0BBDCB" :customStyle="{marginRight: '30rpx'}" label="禁用"
								name="0"></u-radio>
							<u-radio activeColor="#0BBDCB" label="启用" name="1"></u-radio>
						</u-radio-group>
					</view>
				</view>
				<view class="inputbox margin_top" v-if="spDanWeida">
					<view class="flexleft flex1">
						<view class="strongtext margin_right">大单位换算</view>
					</view>
					<view class="itembox">
						<input type="number" placeholder="请输入" v-model="big_to_small_num">
					</view>
				</view>
				<view class="inputbox margin_top" v-if="spDanWeizhong">
					<view class="flexleft flex1">
						<view class="strongtext margin_right">中单位换算</view>
					</view>
					<view class="itembox">
						<input type="number" placeholder="请输入" v-model="middle_to_small_num">
					</view>
				</view>
			</view>
		</view>
		<!-- 其他信息 -->
		<view v-show="tabcurrent==1">
			<view class="mainpadding">
				<view class="strongtext">
					<text class="titletext textliner">其他信息</text>
				</view>
			</view>
			<view class="mainpadding ffffff">
				<view class="inputbox margin_top">
					<view class="flexleft flex1">
						<view class="strongtext margin_right">商品排序号</view>
					</view>
					<view class="itembox">
						<input type="digit" placeholder="请输入" v-model="goods_num">
					</view>
				</view>
				<!-- <view class="inputbox margin_top">
					<view class="flexleft flex1">
						<view class="strongtext margin_right">顺序号</view>
					</view>
					<view class="itembox">
						<input type="text" placeholder="请输入" v-model="weigh">
					</view>
				</view> -->
				<view class="inputbox margin_top">
					<view class="flexleft flex1">
						<view class="strongtext margin_right">原产地</view>
					</view>
					<view class="itembox">
						<input type="text" placeholder="请输入" v-model="ycd">
					</view>
				</view>
				<view class="inputbox margin_top" v-show="producedate_status==1">
					<view class="flexleft flex1">
						<view class="strongtext margin_right">保质期天数</view>
					</view>
					<view class="itembox">
						<input type="number" placeholder="请输入" v-model="bzq">
					</view>
				</view>
				<view class="inputbox margin_top" v-show="producedate_status==1">
					<view class="flexleft flex1">
						<view class="strongtext margin_right">临期预警天数</view>
					</view>
					<view class="itembox">
						<input type="number" placeholder="请输入" v-model="lqyj_days">
					</view>
				</view>
				<view class="inputbox margin_top">
					<view class="flexleft flex1">
						<view class="strongtext margin_right">周滞销预警数量</view>
					</view>
					<view class="itembox">
						<input type="number" placeholder="请输入" v-model="zxyj_num">
					</view>
				</view>
				<view class="inputbox margin_top">
					<view class="flexleft flex1">
						<view class="strongtext">是否热卖</view>
					</view>
					<view class="itembox">
						<u-radio-group v-model="is_hot" placement="row" circle>
							<u-radio activeColor="#0BBDCB" :customStyle="{marginRight: '30rpx'}" label="否"
								name="0"></u-radio>
							<u-radio activeColor="#0BBDCB" label="是" name="1"></u-radio>
						</u-radio-group>
					</view>
				</view>
				<view class="inputbox margin_top">
					<view class="flexleft flex1">
						<view class="strongtext">是否新品</view>
					</view>
					<view class="itembox">
						<u-radio-group v-model="is_new" placement="row" circle>
							<u-radio activeColor="#0BBDCB" :customStyle="{marginRight: '30rpx'}" label="否"
								name="0"></u-radio>
							<u-radio activeColor="#0BBDCB" label="是" name="1"></u-radio>
						</u-radio-group>
					</view>
				</view>
				<view class="inputbox margin_top">
					<view class="flexleft flex1">
						<view class="strongtext">是否推荐</view>
					</view>
					<view class="itembox">
						<u-radio-group v-model="is_rec" placement="row" circle>
							<u-radio activeColor="#0BBDCB" :customStyle="{marginRight: '30rpx'}" label="否"
								name="0"></u-radio>
							<u-radio activeColor="#0BBDCB" label="是" name="1"></u-radio>
						</u-radio-group>
					</view>
				</view>
				<view class="inputbox margin_top">
					<view class="flexleft flex1">
						<view class="strongtext">限购类型</view>
					</view>
					<view class="itembox">
						<u-radio-group v-model="xg_type" placement="row" circle>
							<u-radio activeColor="#0BBDCB" :customStyle="{marginRight: '30rpx'}" label="不限"
								name="0"></u-radio>
							<u-radio activeColor="#0BBDCB" :customStyle="{marginRight: '30rpx'}" label="每月"
								name="1"></u-radio>
							<u-radio activeColor="#0BBDCB" :customStyle="{marginRight: '30rpx'}" label="每周"
								name="3"></u-radio>
							<u-radio activeColor="#0BBDCB" :customStyle="{marginRight: '30rpx'}" label="每天"
								name="2"></u-radio>

							<u-radio activeColor="#0BBDCB" label="每月" name="4"></u-radio>
						</u-radio-group>
					</view>
				</view>
				<view class="inputbox margin_top" v-show="xg_type!=0">
					<view class="flexleft flex1">
						<view class="strongtext margin_right">限购数量</view>
					</view>
					<view class="itembox">
						<input type="number" placeholder="请输入" v-model="xg_num">
					</view>
				</view>

				<view class="inputbox margin_top">
					<view class="flexleft flex1">
						<view class="strongtext">是否包邮</view>
					</view>
					<view class="itembox">
						<u-radio-group v-model="is_by" placement="row" circle>
							<u-radio activeColor="#0BBDCB" :customStyle="{marginRight: '30rpx'}" label="否"
								name="0"></u-radio>
							<u-radio activeColor="#0BBDCB" label="是" name="1"></u-radio>
						</u-radio-group>
					</view>
				</view>
				<view class="inputbox margin_top">
					<view class="flexleft flex1">
						<view class="strongtext margin_right">最低购买量</view>
					</view>
					<view class="itembox">
						<input type="number" placeholder="请输入" v-model="small_buy_num">
					</view>
				</view>
				
				<view class="inputbox margin_top">
					<view class="flexleft flex1">
						<view class="strongtext">是否仅兑换礼品</view>
					</view>
					<view class="itembox">
						<u-radio-group v-model="is_scoredh" placement="row" circle>
							<u-radio activeColor="#0BBDCB" :customStyle="{marginRight: '30rpx'}" label="否"
								name="0"></u-radio>
							<u-radio activeColor="#0BBDCB" :customStyle="{marginRight: '30rpx'}" label="是"
								name="1"></u-radio>
							<u-radio activeColor="#0BBDCB" label="可购买可兑换" name="2"></u-radio>
						</u-radio-group>
					</view>
				</view>
			</view>
		</view>
		<!-- 商品图片 -->
		<view v-show="tabcurrent==2">
			<view class="margin_top ffffff">
				<view class="mainpadding">
					<view class="strongtext">
						<text class="titletext textliner">上传缩略图</text>
					</view>
					<view class="xiaohong margin_top2">建议上传尺寸：100*100</view>
				</view>
				<view class="flexleft flex_wrap mainpadding2">
					<view class="select-box margin_top flexcenter" v-for="(item,index) in image" :key="index">
						<view class="upimageicon">
							<image :src="item" mode=""></image>
							<image class="shanchu" src="../../../static/image/system/shanchu3.png"
								@click="deleimgae(image,index)" mode=""></image>
						</view>
					</view>
					<view class="select-box margin_top flexcenter" v-if="image.length < 1" @click="uploadImg(image,1)">
						<view class="upimageicon">
							<image src="@/static/image/system/upimageicon.png" mode=""></image>
						</view>
					</view>
				</view>
			</view>
			<view class="margin_top ffffff">
				<view class="mainpadding">
					<view class="strongtext">
						<text class="titletext textliner">上传主图</text>
					</view>
					<view class="xiaohong margin_top2">建议上传尺寸：430*330</view>
				</view>
				<view class="flexleft flex_wrap mainpadding2">
					<view class="select-box margin_top flexcenter" v-for="(item,index) in images" :key="index">
						<view class="upimageicon">
							<image :src="item" mode=""></image>
							<image class="shanchu" src="../../../static/image/system/shanchu3.png"
								@click="deleimgae(images,index)" mode=""></image>
						</view>
					</view>
					<view class="select-box margin_top flexcenter" v-if="images.length < 3"
						@click="uploadImg(images,3)">
						<view class="upimageicon">
							<image src="@/static/image/system/upimageicon.png" mode=""></image>
						</view>
					</view>
				</view>
			</view>
			<view class="margin_top ffffff">
				<view class="mainpadding">
					<view class="strongtext">
						<text class="titletext textliner">上详情图</text>
					</view>
				</view>
				<view class="flexleft flex_wrap mainpadding2">
					<view class="select-box margin_top flexcenter" v-for="(item,index) in content_images" :key="index">
						<view class="upimageicon">
							<image :src="item" mode=""></image>
							<image class="shanchu" src="../../../static/image/system/shanchu3.png"
								@click="deleimgae(content_images,index)" mode=""></image>
						</view>
					</view>
					<view class="select-box margin_top flexcenter" v-if="content_images.length < 3"
						@click="uploadImg(content_images,3)">
						<view class="upimageicon">
							<image src="@/static/image/system/upimageicon.png" mode=""></image>
						</view>
					</view>
				</view>
			</view>
		</view>
		<selectSPPinPai :message="{spPinPaiShow:spPinPaiShow}" @spPinPaiSure="spPinPaiSure"></selectSPPinPai>
		<!-- 选择商品品牌 -->
		<selectSPFenLei :message="{spFenLeiShow:spFenLeiShow}" @spFenLeiSure="spFenLeiSure"></selectSPFenLei>
		<!-- 选择商品分类 -->
		<selectSPDanWei :message="{spDanWeiShow:spDanWeiShow,spDanWeiSTatus:spDanWeiSTatus}"
			@spDanWeiSure="spDanWeiSure"></selectSPDanWei><!-- 选择商品单位 -->
	</view>
</template>

<script>
	const httpRequest = require("@/common/httpRequest.js")
	export default {
		data() {
			return {
				list1: [{
					name: '基本信息',
				}, {
					name: '其他信息',
				}, {
					name: '图片信息'
				}, ],
				tabcurrent: 0,
				photoimg: [],
				// *********************基本信息开始
				// 商品品牌
				spPinPaiShow: false,
				spPinPaiText: "",
				goods_brand_id: "", //商品品牌id
				// 商品分类
				spFenLeiShow: false,
				spFenLeiText: "",
				category_id: "", //商品分类id
				// 单位选择
				spDanWeiShow: false,
				spDanWeiSTatus: 1, //1选择小单位，2选择中单位，3选择大单位
				spDanWeixiao: "", //小单位
				small_goods_unit_id: "",
				spDanWeizhong: "", //中单位
				middle_goods_unit_id: "",
				spDanWeida: "", //大单位
				big_goods_unit_id: "",
				name: "",
				zj_name: "",
				allow_gj: "1",
				status: "normal",
				small_goods_unit_code: "",
				middle_goods_unit_code: "",
				big_goods_unit_code: "",
				producedate_status: "0",
				big_to_small_num: "", //大单位换算数量
				middle_to_small_num: "", //中单位换算数量
				goods_num: "",
				weigh: "",
				ycd: "",
				bzq: "",
				lqyj_days: "",
				zxyj_num: "",
				image: [], //缩略图
				is_hot: "1",
				is_new: "1",
				is_rec: "1",
				is_jx: "1",
				xg_num: "",
				xg_type: "0",
				is_by: "1",
				small_buy_num: "1",
				xcx_status: "normal",
				is_scoredh: "0",
				images: [], //主图
				content_images: [], //详情图
				spec: {
					bigdata: { //大单位信息
						pf_price: "",
						price: "",
						min_price: "",
						purchase_price: "",
						cost_price: "",
						weigh: "",
						yg_stock: "",
						dh_score: "",
						buy_send_score: "",
					},
					middledata: { //中单位信息
						pf_price: "",
						price: "",
						min_price: "",
						purchase_price: "",
						cost_price: "",
						weigh: "",
						yg_stock: "",
						dh_score: "",
						buy_send_score: "",
					},
					smalldata: { //小单位信息
						pf_price: "",
						price: "",
						min_price: "",
						purchase_price: "",
						cost_price: "",
						weigh: "",
						yg_stock: "",
						dh_score: "",
						buy_send_score: "",
					}
				},
				listid: "",
				titletext: "添加商品档案"
			}
		},
		onLoad(options) {
			if (options.id) {
				this.listid = options.id
				this.getdetail()
				this.titletext = "编辑商品档案"
			}
		},
		methods: {

			scanbarCode(val) {
				let that = this
				// 允许从相机和相册扫码
				uni.scanCode({
					success: function(res) {
						// console.log('条码类型：' + res.scanType);
						// console.log('条码内容：' + res.result);
						if (val == 1) that.small_goods_unit_code = res.result
						if (val == 2) that.big_goods_unit_code = res.result
						if (val == 3) that.middle_goods_unit_code = res.result
					},
					fail(err) {
						console.log('错误信息：' + err);
					}
				});
			},
			getdetail() {
				httpRequest.request('/dhtapi/goods/detail', 'POST', {
					id: this.listid
				}, false, false, true).then(res => {
					let data = res.data
					this.name = data.name;
					this.big_goods_unit_id = data.big_goods_unit_id;
					this.zj_name = data.zj_name;
					this.category_id = data.category_id;
					this.goods_brand_id = data.goods_brand_id;
					this.allow_gj = data.allow_gj;
					this.status = data.status;
					this.small_goods_unit_code = data.small_goods_unit_code;
					this.small_goods_unit_id = data.small_goods_unit_id;
					this.middle_goods_unit_code = data.middle_goods_unit_code;
					this.middle_goods_unit_id = data.middle_goods_unit_id;
					this.big_goods_unit_code = data.big_goods_unit_code;
					this.producedate_status = data.producedate_status;
					this.big_to_small_num = data.big_to_small_num;
					this.middle_to_small_num = data.middle_to_small_num;
					this.goods_num = data.goods_num;
					this.weigh = data.weigh;
					this.ycd = data.ycd;
					this.bzq = data.bzq;
					this.lqyj_days = data.lqyj_days;
					this.zxyj_num = data.zxyj_num;
					this.image = data.image_text.split(',');
					this.is_hot = data.is_hot==1?"1":"0";
					this.is_new = data.is_new;
					this.is_rec = data.is_rec;
					this.is_jx = data.is_jx;
					this.xg_num = data.xg_num;
					this.xg_type = data.xg_type;
					this.is_by = data.is_by;
					this.small_buy_num = data.small_buy_num;
					this.xcx_status = data.xcx_status;
					this.is_scoredh = data.is_scoredh;
					this.images = data.images_text;
					this.content_images = data.content_images_text;
					this.spPinPaiText = data.goodsbrand.name;
					this.spFenLeiText = data.category.name;
					this.spDanWeixiao = data.smallgoodsunit.name
					this.spec.smalldata = { //小单位信息
						pf_price: data.smallgoodsunit.goods_sku_info.pf_price,
						price: data.smallgoodsunit.goods_sku_info.price,
						min_price: data.smallgoodsunit.goods_sku_info.min_price,
						purchase_price: data.smallgoodsunit.goods_sku_info.purchase_price,
						cost_price: data.smallgoodsunit.goods_sku_info.cost_price,
						weigh: data.smallgoodsunit.goods_sku_info.weigh,
						yg_stock: data.smallgoodsunit.goods_sku_info.yg_stock,
						dh_score: data.smallgoodsunit.goods_sku_info.dh_score,
						buy_send_score: data.smallgoodsunit.goods_sku_info.buy_send_score,
					}
					if (data.middle_goods_unit_id) {
						this.spDanWeizhong = data.middlegoodsunit.name
						this.spec.middledata = { //中单位信息
							pf_price: data.middlegoodsunit.goods_sku_info.pf_price,
							price: data.middlegoodsunit.goods_sku_info.price,
							min_price: data.middlegoodsunit.goods_sku_info.min_price,
							purchase_price: data.middlegoodsunit.goods_sku_info.purchase_price,
							cost_price: data.middlegoodsunit.goods_sku_info.cost_price,
							weigh: data.middlegoodsunit.goods_sku_info.weigh,
							yg_stock: data.middlegoodsunit.goods_sku_info.yg_stock,
							dh_score: data.middlegoodsunit.goods_sku_info.dh_score,
							buy_send_score: data.middlegoodsunit.goods_sku_info.buy_send_score,
						}
					}
					if (data.big_goods_unit_id) {
						this.spDanWeida = data.biggoodsunit.name
						this.spec.bigdata = { //大单位信息
							pf_price: data.biggoodsunit.goods_sku_info.pf_price,
							price: data.biggoodsunit.goods_sku_info.price,
							min_price: data.biggoodsunit.goods_sku_info.min_price,
							purchase_price: data.biggoodsunit.goods_sku_info.purchase_price,
							cost_price: data.biggoodsunit.goods_sku_info.cost_price,
							weigh: data.biggoodsunit.goods_sku_info.weigh,
							yg_stock: data.biggoodsunit.goods_sku_info.yg_stock,
							dh_score: data.biggoodsunit.goods_sku_info.dh_score,
							buy_send_score: data.biggoodsunit.goods_sku_info.buy_send_score,
						}

					}
				})
			},
			submit() {
				if (this.name == "") {
					httpRequest.toast("请输入商品名称");
					return false;
				}
				if (this.category_id == "") {
					httpRequest.toast("请选择商品分类");
					return false;
				}
				if (this.goods_brand_id == "") {
					httpRequest.toast("请选择商品品牌");
					return false;
				}
				if (this.small_goods_unit_id == "") {
					httpRequest.toast("请选择商品小单位");
					return false;
				}
				if (this.small_goods_unit_id != "") {
					let smalldata = this.spec.smalldata
					let smalldataText = "小单位"
					if (smalldata.pf_price == "") {
						httpRequest.toast("请输入" + smalldataText + "批发价");
						return false;
					}
					if (smalldata.price == "") {
						httpRequest.toast("请输入" + smalldataText + "零售价");
						return false;
					}
					if (smalldata.min_price == "") {
						httpRequest.toast("请输入" + smalldataText + "最低零售价格");
						return false;
					}
					if (smalldata.purchase_price == "") {
						httpRequest.toast("请输入" + smalldataText + "进价");
						return false;
					}
					if (smalldata.cost_price == "") {
						httpRequest.toast("请输入" + smalldataText + "成本价格");
						return false;
					}
					// if (smalldata.weigh == "") {
					// 	httpRequest.toast("请输入" + smalldataText + "商品重量");
					// 	return false;
					// }
					// if (smalldata.yg_stock == "") {
					// 	httpRequest.toast("请输入" + smalldataText + "预警库存");
					// 	return false;
					// }
					// if (smalldata.dh_score == "") {
					// 	httpRequest.toast("请输入" + smalldataText + "兑换积分");
					// 	return false;
					// }
					// if (smalldata.buy_send_score == "") {
					// 	httpRequest.toast("请输入" + smalldataText + "购买赠送积分");
					// 	return false;
					// }
				}
				if (this.middle_goods_unit_id != "") {
					let middledata = this.spec.middledata
					let middledataText = "中单位"
					if (middledata.pf_price == "") {
						httpRequest.toast("请输入" + middledataText + "批发价");
						return false;
					}
					if (middledata.price == "") {
						httpRequest.toast("请输入" + middledataText + "零售价");
						return false;
					}
					if (middledata.min_price == "") {
						httpRequest.toast("请输入" + middledataText + "最低零售价格");
						return false;
					}
					if (middledata.purchase_price == "") {
						httpRequest.toast("请输入" + middledataText + "进价");
						return false;
					}
					if (middledata.cost_price == "") {
						httpRequest.toast("请输入" + middledataText + "成本价格");
						return false;
					}
					// if (middledata.weigh == "") {
					// 	httpRequest.toast("请输入" + middledataText + "商品重量");
					// 	return false;
					// }
					// if (middledata.yg_stock == "") {
					// 	httpRequest.toast("请输入" + middledataText + "预警库存");
					// 	return false;
					// }
					// if (middledata.dh_score == "") {
					// 	httpRequest.toast("请输入" + middledataText + "兑换积分");
					// 	return false;
					// }
					// if (middledata.buy_send_score == "") {
					// 	httpRequest.toast("请输入" + middledataText + "购买赠送积分");
					// 	return false;
					// }
				}
				if (this.big_goods_unit_id != "") {
					let bigdata = this.spec.bigdata
					let bigdataText = "大单位"
					if (bigdata.pf_price == "") {
						httpRequest.toast("请输入" + bigdataText + "批发价");
						return false;
					}
					if (bigdata.price == "") {
						httpRequest.toast("请输入" + bigdataText + "零售价");
						return false;
					}
					if (bigdata.min_price == "") {
						httpRequest.toast("请输入" + bigdataText + "最低零售价格");
						return false;
					}
					if (bigdata.purchase_price == "") {
						httpRequest.toast("请输入" + bigdataText + "进价");
						return false;
					}
					if (bigdata.cost_price == "") {
						httpRequest.toast("请输入" + bigdataText + "成本价格");
						return false;
					}
					// if (bigdata.weigh == "") {
					// 	httpRequest.toast("请输入" + bigdataText + "商品重量");
					// 	return false;
					// }
					// if (bigdata.yg_stock == "") {
					// 	httpRequest.toast("请输入" + bigdataText + "预警库存");
					// 	return false;
					// }
					// if (bigdata.dh_score == "") {
					// 	httpRequest.toast("请输入" + bigdataText + "兑换积分");
					// 	return false;
					// }
					// if (bigdata.buy_send_score == "") {
					// 	httpRequest.toast("请输入" + bigdataText + "购买赠送积分");
					// 	return false;
					// }
				}
				if (!this.save()) {
					return false;
				}
				if (this.goods_num == "") {
					httpRequest.toast("请输入商品排序号");
					return false;
				}
				// if (this.weigh == "") {
				// 	httpRequest.toast("请输入商品顺序号");
				// 	return false;
				// }
				// if (this.ycd == "") {
				// 	httpRequest.toast("请输入商品原产地");
				// 	return false;
				// }
				if (this.producedate_status == 1) {
					if (this.bzq == "") {
						httpRequest.toast("请输入商品保质期");
						return false;
					}
					if (this.lqyj_days == "") {
						httpRequest.toast("请输入商品临期预警天数");
						return false;
					}
				}

				// if (this.zxyj_num == "") {
				// 	httpRequest.toast("请输入商滞销预警数量");
				// 	return false;
				// }
				if (this.xg_type != 0) {
					if (this.xg_num == "") {
						httpRequest.toast("请输入商品限购数量");
						return false;
					}
				}

				if (this.small_buy_num == "") {
					httpRequest.toast("请输入商品最低购买量");
					return false;
				}
				if (this.image == "") {
					httpRequest.toast("请上传商品缩略图");
					return false;
				}
				// if (this.images == "") {
				// 	httpRequest.toast("请上传商品主图");
				// 	return false;
				// }
				// if (this.content_images == "") {
				// 	httpRequest.toast("请上传商品详情图");
				// 	return false;
				// }
				let data = {
					goodsinfo: {
						name: this.name,
						zj_name: this.zj_name,
						category_id: this.category_id,
						goods_brand_id: this.goods_brand_id,
						allow_gj: this.allow_gj,
						status: this.status,
						small_goods_unit_code: this.small_goods_unit_code,
						small_goods_unit_id: this.small_goods_unit_id,
						middle_goods_unit_code: this.middle_goods_unit_code,
						middle_goods_unit_id: this.middle_goods_unit_id,
						big_goods_unit_code: this.big_goods_unit_code,
						big_goods_unit_id: this.big_goods_unit_id,
						producedate_status: this.producedate_status,
						big_to_small_num: this.big_to_small_num,
						middle_to_small_num: this.middle_to_small_num,
						goods_num: this.goods_num,
						weigh: this.weigh,
						ycd: this.ycd,
						bzq: this.bzq,
						lqyj_days: this.lqyj_days,
						zxyj_num: this.zxyj_num,
						image: this.image.join(),
						is_hot: this.is_hot,
						is_new: this.is_new,
						is_rec: this.is_rec,
						is_jx: this.is_jx,
						xg_num: this.xg_num,
						xg_type: this.xg_type,
						is_by: this.is_by,
						small_buy_num: this.small_buy_num,
						xcx_status: this.xcx_status,
						is_scoredh: this.is_scoredh,
						images: this.images.join(),
						content_images: this.content_images.join(),
						id: this.listid,
					},
					spec: this.spec
				}
				let url = ""
				if (!this.listid) {
					url = "/dhtapi/goods/addGoods"
					delete data.goodsinfo.id
				} else {
					url = "/dhtapi/goods/editGoods"
				}
				httpRequest.request(url, 'POST', data, false, false, true).then(res => {
					httpRequest.toast(res.msg)
					if (res.code == 1) {
						setTimeout(() => {
							uni.navigateBack(1)
						}, 1000)
					}
				})
			},
			// 单位换算计算
			save() {
				if (this.big_to_small_num == "" && this.spDanWeida != "") {
					httpRequest.toast("请输入大单位换算值")
					return false
				}
				if (this.middle_to_small_num == "" && this.spDanWeizhong != "") {
					httpRequest.toast("请输入中单位换算值")
					return false
				}
				if (this.big_to_small_num != "" && this.middle_to_small_num != "") {
					if (Number(this.big_to_small_num) % Number(this.middle_to_small_num) != 0) {
						httpRequest.toast("大单位换算值必须是中单位换算值的整数倍")
						return false
					}
				}
				return true
			},
			spPinPaiSure(e) { //商品品牌
				if (e) {
					this.spPinPaiText = e.value[0].name
					this.goods_brand_id = e.value[0].id
				}
				this.spPinPaiShow = false
			},
			spFenLeiSure(e) { //商品分类
				if (e) {
					this.spFenLeiText = e.spFenLeiText
					this.category_id = e.category_id
				}
				this.spFenLeiShow = false
			},
			spDanWeiSure(e) { //商品单位
				if (e) {
					if (this.spDanWeiSTatus == 1) {
						this.spDanWeixiao = e.value[0].name //小单位
						this.small_goods_unit_id = e.value[0].id
					}
					if (this.spDanWeiSTatus == 2) {
						this.spDanWeizhong = e.value[0].name //中单位
						this.middle_goods_unit_id = e.value[0].id
					}
					if (this.spDanWeiSTatus == 3) {
						this.spDanWeida = e.value[0].name //大单位
						this.big_goods_unit_id = e.value[0].id
					}
				}
				this.spDanWeiShow = false
			},
			// 选择单位，1小单位，2中单位，3大单位
			selechDanWeiFn(value) {
				this.spDanWeiSTatus = value
				this.spDanWeiShow = true
			},
			tabfn(e) {
				this.tabcurrent = e.index
			},
			// 删除上传图片
			deleimgae(value, index) {
				value.splice(index, 1)
			},
			uploadImg(upImgs, value) {
				let _this = this;
				let num = value - upImgs.length;
				if (num <= 0) {
					return false;
				}
				uni.showActionSheet({
					itemList: ['相机', '相册'],
					success: function(res) {
						// console.log(res)
						// 选择相机走0
						if (res.tapIndex == 0) {
							httpRequest.chooseImage(num, ['camera']).then(res => {
								for (var i = 0; i < res.length; i++) {
									_this.uploadImageService(res[i], upImgs)
								}
							}).catch(err => {});
						}
						// 选择相册走1
						if (res.tapIndex == 1) {
							httpRequest.chooseImage(num, ['album']).then(res => {
								for (var i = 0; i < res.length; i++) {
									// console.log(res[i])
									_this.uploadImageService(res[i], upImgs)
								}
							}).catch(err => {});
						}
					},
					fail: function(res) {}
				});
			},
			// 详情转载
			uploadImageService(url, upImg) {
				// // console.log(url,888)
				let _this = this;
				httpRequest.uploadFile('/api/common/upload', url).then(res => {
					console.log(res);
					let image_item = res.fullurl;
					// this.photoimg = image_item;
					upImg.push(image_item)
				}).catch(err => {});
			},
		}
	}
</script>

<style lang="scss" scoped>
	.iteminput {
		width: 48%;
		box-sizing: border-box;

		input {
			max-width: 100rpx;
			color: #0BBDCB;
		}
	}

	.itemsku {
		background-color: #f7f7f7;
		color: #999;

	}

	// 上传图片
	.scimage {
		width: 100%;
		height: 300rpx;
		box-sizing: border-box;
		background-color: #f4fbfb;

		image {
			width: 100%;
			height: 100%;
		}
	}

	// 内容
	.flex1 {
		flex: 3;
	}

	.inputbox {
		display: flex;
		align-items: flex-start;
		justify-content: space-between;
	}

	.itembox {
		flex: 7;
		width: 100%;
		padding-bottom: 20rpx;
		border-bottom: 1rpx solid rgba(153, 153, 153, 0.06);
	}

	.smalltext {
		font-size: 32rpx;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 500;
		color: #777;
	}

	.numinput {
		width: 200rpx;
		color: #0BBDCB;
	}

	.strongtext {
		line-height: 42rpx;
	}

	// 陈列拍照
	.upimageicon {
		position: relative;
		width: 180rpx;
		height: 180rpx;
		border-radius: 20rpx;

		image {
			border-radius: 20rpx;
			width: 100%;
			height: 100%;
		}
	}

	.shanchu {
		width: 31rpx !important;
		height: 30rpx !important;
		position: absolute;
		left: 40%;
		bottom: -7%;
	}

	// 选择
	.select-box {
		width: 33.33%;
	}
</style>